Ext.ns("ContractConfigView");
var ContractConfigView = function() {
	return this.setup();
};
ContractConfigView.prototype.setup = function() {
	return this.grid();
};
ContractConfigView.prototype.grid = function() {
	var e = new Ext.grid.CheckboxSelectionModel();
	var a = new Ext.grid.ColumnModel(
			{
				columns : [
						e,
						new Ext.grid.RowNumberer(),
						{
							header : "configId",
							dataIndex : "configId",
							hidden : true
						},
						{
							header : "零部件名称",
							width : 100,
							dataIndex : "itemName",
							editor : new Ext.form.TextField({
								allowBlank : false
							})
						},
						{
							header : "规格",
							width : 100,
							dataIndex : "itemSpec",
							editor : new Ext.form.TextField({
								allowBlank : false
							})
						},
						{
							header : "数量",
							width : 60,
							dataIndex : "amount",
							editor : new Ext.form.NumberField({
								allowBlank : false
							})
						},
						{
							header : "备注",
							width : 120,
							dataIndex : "notes",
							editor : new Ext.form.TextField({})
						},
						{
							header : "管理",
							dataIndex : "configId",
							width : 65,
							sortable : false,
							renderer : function(i, h, f, k, g) {
								var j = '<button title="删除" value=" " class="btn-del" onclick="ContractConfigView.remove('
										+ k + ')">&nbsp</button>';
								return j;
							}
						} ],
				defaults : {
					sortable : true,
					menuDisabled : false,
					width : 100
				}
			});
	var b = this.store();
	var d = new Ext.ux.grid.RowEditor({
		saveText : "Update"
	});
	var c = new Ext.grid.EditorGridPanel({
		id : "ContractConfigGrid",
		tbar : this.topbar(),
		store : b,
		plugins : [ d ],
		trackMouseOver : true,
		disableSelection : false,
		loadMask : true,
		width : 450,
		height : 293,
		clicksToEdit : 1,
		cm : a,
		sm : e,
		viewConfig : {
			forceFit : true,
			enableRowBody : false,
			showPreview : false
		}
	});
	return c;
};
ContractConfigView.prototype.store = function() {
	var a = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : __ctxPath + "/contract/listContractConfig.do"
		}),
		reader : new Ext.data.JsonReader({
			root : "result",
			totalProperty : "totalCounts",
			id : "ContractConfigViewStoreId",
			fields : [ {
				name : "configId",
				type : "long"
			}, "itemName", "itemSpec", {name:"amount",type:"int"}, "notes" ]
		}),
		remoteSort : true
	});
	a.setDefaultSort("configId", "desc");
	return a;
};
ContractConfigView.prototype.topbar = function() {
	var a = new Ext.Toolbar({
		id : "ContractConfigFootBar",
		height : 28,
		bodyStyle : "text-align:left",
		items : [ {
			iconCls : "btn-add",
			text : "添加零部件",
			xtype : "button",
			handler : function() {
				var d = Ext.getCmp("ContractConfigGrid");
				var b = d.getStore();
				var c = d.getStore().recordType;
				var e = new c();
				d.stopEditing();
				b.insert(b.getCount(), e);
				b.sort();
				d.getView().refresh();
				d.startEditing(0, 0);
			}
		}, {
			iconCls : "btn-del",
			text : "删除零部件",
			xtype : "button",
			handler : function() {
				var e = Ext.getCmp("ContractConfigGrid");
				e.stopEditing();
				var b = e.getSelectionModel().getSelections();
				var c = e.getStore();
				if (b.length == 0) {
					Ext.ux.Toast.msg("信息", "请选择要删除的记录！");
					return;
				}
				var f = e.getSelectionModel().getSelections();
				for (var d = 0, g; g = f[d]; d++) {
					c.remove(g);
				}
				c.sort();
				e.getView().refresh();
				e.startEditing(0, 0);
			}
		} ]
	});
	return a;
};
ContractConfigView.remove = function(e) {
	var b = Ext.getCmp("ContractConfigGrid");
	b.stopEditing();
	var c = b.getSelectionModel().getSelections();
	for (var a = 0, d; d = c[a]; a++) {
		b.getStore().remove(d);
	}
	b.getView().refresh();
	b.startEditing(0, 0);
};